package com.whut.coc.entity;

import lombok.Data;

import java.io.Serial;
import java.io.Serializable;

/**
 * @author wangzonghe
 * @date 2025/6/20 15:29
 */
@Data
public class Result<T extends Serializable> implements Serializable {

    @Serial
    private static final long serialVersionUID = 1L;

    /**
     * 状态码 0-成功 其他数字-失败
     */
    private Integer code;

    /**
     * 错误信息
     */
    private String msg;

    /**
     * 数据
     */
    private T data;

    public static <T extends Serializable> Result<T> success() {
        Result<T> result = new Result<>();
        result.setMsg("success");
        result.setCode(0);
        return result;
    }

    public static <T extends Serializable> Result<T> success(T object) {
        Result<T> result = new Result<>();
        result.setData(object);
        result.setCode(0);
        result.setMsg("success");
        return result;
    }

    public static <T extends Serializable> Result<T> error(String msg) {
        Result<T> result = new Result<>();
        result.setMsg(msg);
        result.setCode(-1);
        return result;
    }
}